package org.techmore.bussiness;

import java.util.ArrayList;
import java.util.List;

import org.techmore.common.utils.properties.PropertiesUtil;
import org.techmore.valueobject.QuestionVO;

public class QuestionsBeanDataHandler {
	
	private static QuestionsBeanDataHandler questionsBeanDataHandler = new QuestionsBeanDataHandler();
	private static int questionIndex = 0;
	private static int totalScore = 0;
	
	private static int questionsSize = Integer.parseInt(PropertiesUtil.getInstance().getValue("questionsSize"));
	private static int questionScore = Integer.parseInt(PropertiesUtil.getInstance().getValue("questionScore"));
	
	public static QuestionsBeanDataHandler getInstance() {
		return questionsBeanDataHandler;
	}
	
	private static List<QuestionVO> questionList = null;
	
	private void initQuestionList(){
		questionList = new ArrayList<QuestionVO>();
		questionList.clear();
	}
	
	public void addQuestion(QuestionVO questionVO){
		if(null == questionList){
			initQuestionList();
		}
		questionList.add(questionVO);
	}
	
	public void clearQuestions(){
		if(null != questionList){
			questionList.clear();
		}
	}
	
	public int getQuestionListSize(){
		return questionList.size();
	}
	
	public int getQuestionIndex(){
		return questionIndex;
	}
	
	public int increaseQuestionIndex(){
		questionIndex++;
		if(questionIndex<questionsSize){
			return -1;
		}else{
//			refreshIndex();
			return -2;
		}
		
	}
	
	public void refreshIndex(){
		questionIndex = 0;
	}
	
	public QuestionVO getQuestionVO(int index){
		return questionList.get(index);
	}

	public void increaseTotalScore(){
		totalScore+=questionScore;
	}
	public void refreshTotalScore(){
		totalScore = 0;
	}
	public int getTotalScore(){
		return totalScore;
	}
	
	
	public int getQuestionsSize() {
		return questionsSize;
	}
	public int getQuestionScore() {
		return questionScore;
	}


}
